home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume24 / psroff3.0 / part09 < prev    next >
Encoding:
Internet Message Format  |  1991-10-09  |  55.9 KB

  1. Subject:  v24i104:  psroff, Troff to PostScript filter, Part09/19
  2. Newsgroups: comp.sources.unix
  3. Approved: rsalz@uunet.UU.NET
  4.  
  5. Submitted-by: Chris Lewis <latour!ecicrl!clewis@uunet.uu.net>
  6. Posting-number: Volume 24, Issue 104
  7. Archive-name: psroff3.o/part09
  8.  
  9. #! /bin/sh
  10. # This is a shell archive.  Remove anything before this line, then feed it
  11. # into a shell via "sh file" or similar.  To overwrite existing files,
  12. # type "sh file -c".
  13. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  14. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  15. # Contents:  MISC defs.h man/psroff.1.S utils/calcfonts.S
  16. #   widths/dit2catwid.c
  17. # Wrapped by clewis@ecicrl on Fri Apr  5 20:56:00 1991
  18. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  19. echo If this archive is complete, you will see the following message:
  20. echo '          "shar: End of archive 9 (of 19)."'
  21. if test -f 'MISC' -a "${1}" != "-c" ; then 
  22.   echo shar: Will not clobber existing file \"'MISC'\"
  23. else
  24.   echo shar: Extracting \"'MISC'\" \(10084 characters\)
  25.   sed "s/^X//" >'MISC' <<'END_OF_FILE'
  26. X        Miscellaneous Tuning/Customization
  27. X            2.9 91/03/26
  28. X
  29. X    - Postscript spooling:  Theoretically speaking, it is better
  30. X      to have psxlate in your Postscript printer spooler interface
  31. X      than as a pipeline in psroff.  For System V, you might want
  32. X      to insert psxlate as the filter (instead of the more-usual
  33. X      cat) in the interface file when you're passing postscript through
  34. X      to the printer.  On lpr-type spoolers, make psxlate the filter
  35. X      program in /etc/printcap.  Then you'll be able to use psxlate's
  36. X      processing on all of your postscript output.
  37. X
  38. X      Notes: psxlate does NOTHING to files without a "%!PS-Adobe-"
  39. X      header.  In other words, psxlate doesn't do anything to files
  40. X      that don't conform to the Document Structuring Conventions.
  41. X      Eventually psxlate will probably permit you to do n-up (but
  42. X      not page flipping) on any file that has a "%!" at the front,
  43. X      and do automatic ASCII to Postscript conversions on files that
  44. X      don't have "%!", further, page flipping and n-up *will* work.
  45. X
  46. X    - psfig: If you have psfig, copy the psfig Postscript prolog
  47. X      to LIBDIR/lib/psfig.ps, and insert the following line at
  48. X      the end of ps.lib:
  49. X    %%%include psfig
  50. X      (psfig.ps is a subset of the psdit prolog fragment given in the
  51. X      "patch" subdirectory in the psfig release - the README tells
  52. X      you which part)
  53. X
  54. X      Psfig works perfectly with ditroff, and should work reasonably
  55. X      well with CAT troff.  Note: most ditroff's have a bug where
  56. X      the horizontal position is not emitted before a \X'...'
  57. X      sequence.  This is seen by diagrams that aren't quite where
  58. X      they should be horizontally - often at the left margin when
  59. X      they should really be centered.  This can be rectified if
  60. X      you have source with a patch for ditroff that comes bundled with
  61. X      psfig.  If you do not have ditroff source, the psfig option "-fts"
  62. X      (not mentioned in the man page for psfig) will compensate for the
  63. X      problem, at the expense of losing the ability to use the \(ts character.
  64. X      The -fts option is ALWAYS required with CAT troff.  See "catconv"
  65. X      below.
  66. X
  67. X      (Note: In the psfig document under the "doc" directory in the
  68. X      psfig release, page 10 contains a MACWrite generated figure.
  69. X      Near the end of page 10 there is a bit of postscript that
  70. X      most postscript printers don't like (a findfont) - print aborts
  71. X      at this point are NOT the fault of psroff, but a fault in the
  72. X      postscript that psfig has included).
  73. X
  74. X    - catconv: catconv converts ditroff-only-isms into something handled
  75. X      by psroff.  In order for you to use this, you have to have a copy
  76. X      of perl installed on your machine.  This isn't completely
  77. X      integrated into psroff, so here are a few things to consider:
  78. X    - the catconv script's startup (the #!/usr/bin/perl stuff)
  79. X      may have to be changed to reflect your perl install configuration.
  80. X    - If you specify "v=1" in the psrofflib entry, psroff will
  81. X      arrange to invoke catconv properly, so that you don't have
  82. X      to manually invoke catconv - the "cdps" entry has an example.
  83. X      If you are using CAT troff, if you cannot use catconv, you will
  84. X      not be able to use psfig, \X'...' commands, \D'....' commands
  85. X      (PIC) or the extended character set.
  86. X
  87. X    - HPLJ tuning:
  88. X    bestmatch: in lj.c's bestmatch function there is are arrays
  89. X        "bigtry" and "smalltry".  These arrays provide a scan
  90. X        sequence finding a font size "close" to a requested font
  91. X        size that lj.fonts indicates isn't present.  If there
  92. X        are holes in your fonts, you may want to experiment with
  93. X        these arrays.
  94. X    tbl box corners: depending on where you got your fonts from,
  95. X        you may have to slightly adjust the box drawing characters
  96. X        to match up at the corners of tbl boxes.  To do this,
  97. X        append to lj.fonts:
  98. X
  99. X        normal
  100. X        ru N _ 0 -200
  101. X        symbol
  102. X        br N | -220 0
  103. X
  104. X        The two numbers are the X and Y shifts of the corresponding
  105. X        characters, where the numbers are scaled by (.01 * pointsize)
  106. X        to get a shift in 1/720'ds.  Adjust these (carefully examine
  107. X        tbl output to decide whether you want to move ru or br).
  108. X
  109. X        The distributed defaults (which are shown here) are suitable
  110. X        for HP Times-Roman font floppies.
  111. X
  112. X    - performance: you can preload commonly used fonts into your
  113. X      laserjet and thereby greatly reduce transmission time.
  114. X      Consult the manual page for pk2sfp about the -P, -i, -S and -p
  115. X      options (don't forget to mark the pointsizes you've downloaded
  116. X      as "b" in the lj.fonts file).
  117. X
  118. X    - ditroff tuning: Many of the ditroff converters have slightly
  119. X      different correspondences between what character is in what
  120. X      font.  You may want to modify the *.fonts file that you're
  121. X      using to make sure that every character you want is being
  122. X      printed correctly.  As an example, with tpscript "@" and
  123. X      "^" aren't S font characters - they're in the normal fonts,
  124. X      but the dt.c table says they're "symbol".  To tune for
  125. X      tpscript:
  126. X
  127. X        - modify psrofflib to have "-ptp" option to troff2ps (t2arg).
  128. X        - copy dt.fonts to tp.fonts (in LIBDIR/lib).
  129. X        - append to tp.fonts the following font override sequence:
  130. X
  131. X        symbol
  132. X        ^    N
  133. X        @    N
  134. X
  135. X      psdit and xtroff appear to require the same things to be done
  136. X      for "^" and "@" (psdit prints nothing without these, and xtroff
  137. X      prints some other characters instead).
  138. X
  139. X      Jetroff requires similar things, and jt.fonts has a more
  140. X      extensive example of this.  Font overrides are documented
  141. X      more completely next:
  142. X
  143. X    - If you want to play around with character mappings.....
  144. X      Eg: adding accents for your own language (ie: German)
  145. X      The most important thing to remember is that you cannot extend
  146. X      the CAT's character sets without modifying troff - unlike ditroff
  147. X      where you can add them by changing the makedev files.  This
  148. X      is how you do overrides (see troff2ps(1) for more details):
  149. X
  150. X        - Put in a map override in the appropriate *.fonts file that
  151. X          emits the character you want in place of a character you
  152. X          don't need in the appropriate *.fonts file.  Eg: for
  153. X          "germandbls" in ditroff, emit "ss" instead of "ct" for
  154. X          the cent character.  Your override (in dt.fonts) would
  155. X          look like:
  156. X
  157. X        ct N ss
  158. X
  159. X          The complete override format is:
  160. X
  161. X        <troffchar> N|S|n <sequence> <x adjust> <y adjust> <scale>
  162. X
  163. X          x adjust, y adjust, scale default to 0, 0 and 100 respectively.
  164. X          x and y adjust are multiplied by .01, then the pointsize
  165. X          and of the output driver to give the shift factor in
  166. X          1/resolution units.  Scale allows you to change the size
  167. X          of that one character (eg: you think bullet is too small), but
  168. X          it isn't recommended too much (it may not work reasonably
  169. X          on non-postscript drivers).  Again, scale is prescaled by
  170. X          .01 first, so 100 is 1-1.
  171. X
  172. X          <sequence> defaults to <troffchar>.  N means normal mapping
  173. X          (eg: for fonts other than S with no cross font jumping),
  174. X          S means symbol font, and "n" means specific font (usually >3 -
  175. X          eg: special bracket fonts).
  176. X
  177. X        - Modify the width table for the character you're replacing
  178. X          to have the width for the character you're emitting.
  179. X          Eg: for germandbls in ditroff, replace the "ct" entry's
  180. X          width in widths/widthps/R with the width for "ss".  This
  181. X          latter step is not necessary with laserjets because the
  182. X          build procedure builds a new width table using the
  183. X          remapping.
  184. X
  185. X      With ditroff input (or the use of the "C" special directives - see
  186. X      troff2ps(1)), you can extend the character set as much as you want.
  187. X      You find the entry in the appropriate width files and add in the
  188. X      width entries for your character, and then add them to the
  189. X      "extensions" section of the ??.fonts file.  See ps.fonts for
  190. X      an example.  At present there's no way of getting the width
  191. X      information into CAT troff, but with ditroff everything works well.
  192. X      By adding the entry into the width file, the widths/Makefile
  193. X      will generate a complete set of extension characters in
  194. X      width??/??.ext, which can be appended onto the *.fonts file.
  195. X
  196. X    - Adding fonts after installation:
  197. X    - New Laserjet fonts should be installed in the $LJF directory.
  198. X    - Non-laserjet fonts should have their ditroff width table placed
  199. X      in the proper widths/width?? directory.
  200. X    - Ensure that the appropriate lib/*.fonts file contains the fonts
  201. X      you're adding.
  202. X    - at the top level, type:
  203. X        make register
  204. X    - then
  205. X        su root
  206. X        make installwidths
  207. X
  208. X    - Display Postscript: My display postscript came with the source for
  209. X      a utility called "dpsexec", which is a simple Postscript previewer
  210. X      front end.  The source on a IBM RS/6000 was in:
  211. X    /usr/lpp/DPS/examples/dpsexec/dpsexec.c
  212. X      For best results, you may want to apply the following patch
  213. X      to it (it redefines the initial window to be big enough
  214. X      to contain a standard page, as well as adding a "!" escape to
  215. X      shell in the interrupt handler):
  216. X
  217. X=========== DPSEXEC.C PATCH START ==============
  218. X*** dpsexec.c.orig    Sat Mar  9 02:00:45 1991
  219. X--- dpsexec.c    Mon Mar 11 23:27:32 1991
  220. X***************
  221. X*** 65,72 ****
  222. X  #include <DPS/XDPSlib.h>
  223. X  #include <DPS/dpsXclient.h>
  224. X
  225. X! #define W_HEIGHT    512
  226. X! #define W_WIDTH        512
  227. X
  228. X  static int quitFlag = 0;
  229. X  static unsigned long int enable, next, disable;
  230. X--- 65,72 ----
  231. X  #include <DPS/XDPSlib.h>
  232. X  #include <DPS/dpsXclient.h>
  233. X
  234. X! #define W_HEIGHT    (11*72)
  235. X! #define W_WIDTH        (9*72)
  236. X
  237. X  static int quitFlag = 0;
  238. X  static unsigned long int enable, next, disable;
  239. X***************
  240. X*** 195,200 ****
  241. X--- 195,201 ----
  242. X      printf("\tq\tquit\n");
  243. X      printf("\ti\tinterrupt\n");
  244. X      printf("\tk\tkill\n");
  245. X+     printf("\t!\tshell\n");
  246. X      printf("Command: ");
  247. X      c = getchar(); getchar(); /* eat the newline */
  248. X      switch (c)
  249. X***************
  250. X*** 215,220 ****
  251. X--- 216,224 ----
  252. X          case 'k':
  253. X              command = 6;
  254. X              break;
  255. X+     case '!':
  256. X+         system("/bin/sh");
  257. X+         break;
  258. X      default:;
  259. X          }
  260. X
  261. X=========== DPSEXEC.C PATCH END ======================
  262. END_OF_FILE
  263.   if test 10084 -ne `wc -c <'MISC'`; then
  264.     echo shar: \"'MISC'\" unpacked with wrong size!
  265.   fi
  266.   # end of 'MISC'
  267. fi
  268. if test -f 'defs.h' -a "${1}" != "-c" ; then 
  269.   echo shar: Will not clobber existing file \"'defs.h'\"
  270. else
  271.   echo shar: Extracting \"'defs.h'\" \(11537 characters\)
  272.   sed "s/^X//" >'defs.h' <<'END_OF_FILE'
  273. X/*
  274. X    Copyright 1985, 1986, 1987, 1988, 1989, 1990, 1991 Chris Lewis
  275. X        All Rights Reserved
  276. X
  277. X    See the LICENSE file for a full description of restrictions under which
  278. X    this software is provided.
  279. X
  280. X    Function:    Main header file - contains some customization
  281. X */
  282. X
  283. X/*    Official Release and Patch level:    */
  284. X#define    T2VERSION    "@(#)PSROFF Copyright 91/03/25 Chris Lewis - R3 PL0"
  285. X
  286. X/*    Configuration parameters:
  287. X */
  288. X
  289. X#undef    BSD        /* Define if you are a V7 or BSD machine */
  290. X            /* strchr vs. index etc.... */
  291. X
  292. X#define    ATT        /* Define if you are some sort of SIII or SV system */
  293. X
  294. X#undef    BCOPY        /* Define if you don't have memcpy and friends - eg:
  295. X               oldish BSD systems */
  296. X
  297. X#undef  BCOPYLIB    /* Define if BCOPY is defined and you have */
  298. X            /* a bcopy in your library */
  299. X
  300. X/*    The name of a routine that can be called thusly:
  301. X    VFPRINTF(stream, format, ap)
  302. X    FILE *stream;
  303. X    char *format;
  304. X    va_list ap;
  305. X    (eg: you have varargs.h and you have a routine functionally compatible
  306. X    with System V vfprintf.  I think BSD has one too)
  307. X
  308. X    undef if you don't got, and maybe my fakeout will work.
  309. X */
  310. X
  311. X#define VFPRINTF    vfprintf
  312. X
  313. X/* If you have the stand-alone pk2sfp distribution, do not touch
  314. X   anything from here on */
  315. X
  316. X/*    Font width file configuration:
  317. X
  318. X    - If HEADERSIZE defined, use that many bytes as a prefix to the
  319. X      compiled font width table.  HEADERSIZE 0 is the correct definition
  320. X      for Xenix and most System V [o]troffs.  HEADERSIZE=32 works for Ultrix
  321. X      (except RISC, see below).  HEADERSIZE=32 works properly for most Suns.
  322. X    - If COFF is defined instead, use a COFF header on the beginning of
  323. X      the file.  I personally know of no machine that supports these, tho,
  324. X      there's unconfirmed rumours that Apollo systems might.
  325. X    - If neither are defined, use a BSD/V7 style a.out.h header, this
  326. X      is appropriate for V7 and BSD troffs
  327. X    - If you are running RISC/Ultrix (Mips box? from DEC) define
  328. X      ASCIIWIDTHS, and the rest of this stuff will be ignored - Mips
  329. X      apparently changed their width table format to an ASCII form,
  330. X      and DEC picked it up.  In this case IGNORE any messages about
  331. X      HEADERSIZE from "make check".
  332. X
  333. X    The headers I write will have something in them if HEADERSIZE > 0
  334. X    and there's a font file from your original troff distribution in
  335. X    /usr/lib/font/ftR (the header and trailer will be copied over).
  336. X
  337. X */
  338. X
  339. X#define    HEADERSIZE 0    /* size of header in bytes */
  340. X#undef    COFF        /* systems using COFF headers - See TROUBLE file
  341. X               about Apollos */
  342. X#undef    ASCIIWIDTHS    /* For RISC/Ultrix */
  343. X
  344. X/* What do your CAT codes look like?
  345. X
  346. X   If BSDHACK defined, the code to magnify the next lead by 64 replaces the
  347. X   codes to set the tilt (tilt used only on 8-font CATs, which most CAT troff
  348. X   programs don't support).
  349. X
  350. X   Both FONT8 and BSDHACK code are *untested*.  FONT8 probably does *not*
  351. X   work.
  352. X */
  353. X
  354. X#undef    BSDHACK        /* Has magnify lead opcode - untested */
  355. X#undef    FONT8        /* 8 Font device - untested */
  356. X#define FONT4        /* Normal 4 font device */
  357. X
  358. X            /* define a command for decompressing an argument
  359. X               file to stdout - allows you to compress SFP's.
  360. X               undef if you don't got.  The -d option may be
  361. X               undocumented, but means decompress.  "-dc"
  362. X               is equivalent to zcat.  -dc appears to be
  363. X               in most versions of compress (eg: v3 & v4) */
  364. X#define    COMPRESS    "/usr/lbin/compress -dc"
  365. X
  366. X/*    Some postscript printers don't accept control-D as job termination
  367. X    (DEC scriptwriters for instance, or LAN-connected printers).  In that
  368. X    case, define this macro.  Alternately, if you have a proper printer
  369. X    manager that does this sort of stuff, define it too.
  370. X    If your printer will take "stop", specify "-S" in psrofflib's
  371. X    t2arg, and leave this undefined.
  372. X */
  373. X#undef    NOCONTROLD
  374. X
  375. X/*    define if you don't want your Postscript printer talking to you */
  376. X#undef    NOCHATTER
  377. X
  378. X/*    The only advantage to commenting-out one of these is to make the
  379. X    binary executable of troff2?? smaller.
  380. X */
  381. X
  382. X/*    Basic drivers: */
  383. X#define    PS    /* Postscript */
  384. X#define    LJ    /* Laserjet - utils programs will not build with this undef'd */
  385. X#define    DT    /* ditroff */
  386. X#define    DIT    /* ditroff *front-end* */
  387. X
  388. X/*    Laserjet driver config: */
  389. X#define    PK    /* enable PK font downloading (needs LJ) */
  390. X
  391. X#define    SFP    /* enable SFP incremental font downloading (needs PK).
  392. X           You can still use SFP's without this turned on, but
  393. X           you won't get incremental downloading */
  394. X
  395. X#define    PARTIAL    /* partial (not incremental) font downloading */
  396. X
  397. X#define    INCR    /* enable incremental font downloading (needs PARTIAL) */
  398. X
  399. X#define    MDLF    16    /* Max # downloaded fonts permitted by your laserjet
  400. X               per *page*.  16 is correct for HPLJ+ and most II's.
  401. X               IIP's are 32 I think.  Some newer ones have higher
  402. X               restrictions (don't put this too high even if
  403. X               your printer supports it, you may run out of
  404. X               memory) */
  405. X
  406. X#define    PRELOAD    0    /* set to number of LJ fonts permanently
  407. X               downloaded to printer.  The backend will
  408. X               make sure that you don't go over the number
  409. X               of fonts permitted by the printer */
  410. X
  411. X#define    DEBUG        /* Do you want the debugger in?  If you encounter
  412. X               problems and you want help from me, you'll have
  413. X               to have this turned on */
  414. X
  415. X#define    OPT        /* CAT code reorder and optimizer */
  416. X
  417. X#define    DEFPL  11    /* Default page length (11 inches).
  418. X               DO NOT change unless you absolutely HAVE to.
  419. X               You should only need to change this if you
  420. X               desire your printer to use something different
  421. X               as default.  If so, you'll HAVE to change
  422. X               your macro package to agree on the default - RT
  423. X               owners take note! (the man macros are wrong) */
  424. X
  425. X#define    DEFOFF 0.5    /* Default page offset.  DO NOT change unless you
  426. X               absolutely HAVE to.  You should only need this
  427. X               if: your vendor has buggered your macros to
  428. X               have a different default .po offset (Xenix),
  429. X               and you aren't using the macro adapter
  430. X               libraries that come with psroff (eg: you're
  431. X               using troff2ps directly).  See README/TROUBLE/
  432. X               psroff(1) (-O vs. -rO options) */
  433. X
  434. X#define    DEFYOFF   0    /* Default page vertical offset.  See README/TROUBLE/
  435. X               psroff(1) -Y options too */
  436. X
  437. X#define    INSPECIAL    /* enables ditroff graphics capability */
  438. X
  439. X#define    NSP    256    /* number of \(xx characters. */
  440. X
  441. X#define    NODECMD    "uuname -l" /* command to print on stdout the node name
  442. X               of your machine.  Use hostname on BSD-derived
  443. X               systems that don't have UUCP.  You can always
  444. X               use "echo <nodename>" if necessary */
  445. X
  446. X/*    Edit no more .... */
  447. X
  448. X#define    MAXDLFONTS (MDLF - PRELOAD)    /* # fonts troff2ps can download */
  449. X
  450. X/*    configuration verification */
  451. X
  452. X#if    defined(BSDHACK) && defined(FONT8)
  453. X#include    "BSDHACK and FONT8 cannot be defined at the same time"
  454. X#endif
  455. X#if    defined(FONT4) && defined(FONT8)
  456. X#include    "FONT4 and FONT8 cannot be defined at the same time"
  457. X#endif
  458. X
  459. X#if    !defined(LJ) && defined(PK)
  460. X#include    "Pointless to define PK without LJ"
  461. X#endif
  462. X
  463. X#if    !defined(PK) && (defined(INCR) || defined(PARTIAL))
  464. X#include    "Pointless to define INCR or PARTIAL without PK"
  465. X#endif
  466. X
  467. X#if    defined(INCR) && !defined(PARTIAL)
  468. X#include    "Don't support INCR without PARTIAL"
  469. X#endif
  470. X
  471. X#if    defined(SFP) && !defined(PK)
  472. X#include    "Can't define SFP without PK"
  473. X#endif
  474. X
  475. X#include <stdio.h>
  476. X#include <ctype.h>
  477. X
  478. X#ifdef BSD
  479. X#include <strings.h>
  480. X#define    strchr    index
  481. X#define    strrchr    rindex
  482. X#else
  483. X#include <string.h>
  484. X#endif
  485. X
  486. X#ifdef    BCOPY
  487. X#define    memcpy(to, from, len)    bcopy(from, to, len)
  488. X#define    clrarray(array, len)    bzero(array, len)
  489. X#else
  490. X#define    clrarray(array, len)    memset(array, '\0', len)
  491. X#endif
  492. X
  493. X#define    ESC    0x80
  494. X#define    FLASH    0x00
  495. X#define    CONTROL    0x40
  496. X#define    LEAD    0x60
  497. X#define    SIZE    0x50
  498. X
  499. X#define    DOWN    0
  500. X#define    UP    1
  501. X#define    LOWER    2
  502. X#define    UPPER    3
  503. X#define    FORWARD    4
  504. X#define    BACKWARD 5
  505. X
  506. X#define    TROFFRESOLUTION    432
  507. X
  508. X#define    SPECIAL        /* define if you want to support special directives */
  509. X#define    FORM        /* define if you want the forms facility */
  510. X
  511. XFILE    *diagFile;
  512. X
  513. X#ifdef DEBUG
  514. X#define    DBP(x)    if (diagFile) dprintf x
  515. Xextern dprintf();
  516. X#else
  517. X#define    DBP(x)
  518. X#endif
  519. X
  520. Xtypedef int(*FUNC)();
  521. X
  522. X#define    FNULL    (FUNC) NULL
  523. X
  524. Xstruct    troff2befont {
  525. X    short    t2b_font;    /* font (troff nomenclature) S=don't change */
  526. X    short    t2b_xc;        /* X-shift */
  527. X    short    t2b_yc;        /* Y-shift */
  528. X    short    t2b_scale;    /* point size scale adjust */
  529. X    char     *t2b_charseq;    /* character sequence - may include PS */
  530. X};
  531. X
  532. Xstruct cattab {
  533. X    char *ch_name;
  534. X    char ch_set;
  535. X    unsigned char ch_catidx;
  536. X    unsigned char ch_wididx;
  537. X    unsigned char ch_info;    /* used by some auxiliary programs */
  538. X    char *ch_desc;
  539. X};
  540. X
  541. Xstruct backend {
  542. X    char    *bename;
  543. X    FUNC    beprolog,
  544. X        beepilog,
  545. X        beputchar,
  546. X        bepage,
  547. X        befontsel,    /* special function F */
  548. X        beoverlay,    /* special function O */
  549. X        bepassthru,    /* special function P */
  550. X        bexlat,        /* Xlate function */
  551. X        bedraw;        /* Ditroff draw emulation routine */
  552. X    struct troff2befont
  553. X        *bestdfont,    /* standard font translate table */
  554. X        *besymfont;    /* symbol font translate table */
  555. X};
  556. X
  557. X#define    MAXFONTS    50
  558. X
  559. Xstruct fonttable {
  560. X    char *tab[4];
  561. X    long flags;
  562. X#ifdef    INCR
  563. X    struct downmaps *map;
  564. X#endif
  565. X#ifdef    OPT
  566. X    char *widthtable;
  567. X#endif
  568. X};
  569. X
  570. X/*    Symbolic names for tab entries in fonttable    */
  571. X#define    troffName    tab[0]    /* troff name */
  572. X#define    fontName    tab[1]    /* back-end name (if used) */
  573. X#define    fontSeq        tab[2]    /* sequence to emit to shift to it
  574. X                   lj builtin's mostly */
  575. X
  576. X/*    fontFlags is 16 characters that reflect the state of the font
  577. X    at a particular pointsize - mainly for lj */
  578. X
  579. X/*    Use of flags:
  580. X    s:    unloaded SFP
  581. X    S:    loaded SFP
  582. X    p:    unloaded PK
  583. X    P:    loaded PK
  584. X    n:    non-existant
  585. X    b:    builtin.
  586. X */
  587. X#define    fontFlags    tab[3]
  588. X
  589. Xextern int symidx;        /* index of symbol font */
  590. X
  591. X#define    INTFONTS    10    /* maximum number of builtin fonts */
  592. X
  593. Xextern struct fonttable fonttable[MAXFONTS+1];
  594. Xextern struct fonttable *xlatetable[INTFONTS];
  595. X#define    EXTCHUNK    10
  596. Xextern struct troff2befont *extchars;
  597. Xextern struct cattab **spctab, **dittab;
  598. Xextern struct cattab *extidx;
  599. Xextern int extcount;
  600. Xextern char *pstrailer;
  601. X
  602. Xstruct backend *be;
  603. X#define    BNULL    (struct backend *) NULL
  604. X
  605. Xextern char *skipblanks();
  606. X
  607. X/*    Common Back-end definitions */
  608. X
  609. X#define    N    (unsigned char) (0xff)    /* Use standard font */
  610. X#define    S    (unsigned char) (0xfe)    /* Use symbol font */
  611. X#define    D    (unsigned char) (0xfd)    /* Draw macro exists - use string directly */
  612. X#define    NTC    (unsigned char) (0xfc)    /* No font/Special flag */
  613. X
  614. X#define    NOC    NULL
  615. X
  616. Xextern int currentPage;
  617. Xextern int pageoffset;
  618. Xextern int pageyoffset;
  619. Xextern int pagelength;
  620. Xextern int pagePending;
  621. X
  622. X#ifdef    OPT
  623. Xextern char *widthtables;
  624. Xextern char *widthptr;
  625. Xextern int optimize;
  626. X#endif
  627. X
  628. Xextern int lastFont, lastPoints;
  629. Xextern int lastYPos, lastXPos, specXPos, specYPos;
  630. Xextern char *progname, *printer, *device;
  631. Xextern char **prologs;
  632. X
  633. Xint metrics;
  634. X#ifdef    DIT
  635. Xint ditroff;
  636. X#endif
  637. X
  638. XFILE *libopen();
  639. X
  640. X/*    Encoding format for generating width tables from font files */
  641. X/*    Used by pk2ditwid and friends */
  642. Xstruct enctab {
  643. X    char *e_name;
  644. X    char *e_seq;
  645. X    char e_wid;
  646. X};
  647. X
  648. X/*    Points in an inch */
  649. X#define    POINT    72.27
  650. X
  651. X#define    min(a,b)    ((a) < (b) ? (a) : (b))
  652. X#define    max(a,b)    ((a) > (b) ? (a) : (b))
  653. X
  654. X/* debug flags */
  655. X#define    D_CAT    1    /* show cat interpretation machinery */
  656. X#define    D_SPEC    2    /* show special directives */
  657. X#define    D_CHAR    4    /* optimizer machinery */
  658. X#define    D_FONT    8    /* font handling */
  659. X#define    D_BEND    0x10    /* backend */
  660. X#define    D_PK    0x20    /* PK font handling */
  661. X#define    D_VERB    0x40    /* very verbose */
  662. X#define    D_FLSH    0x80    /* flush after each fprintf */
  663. X
  664. Xextern int debug;
  665. X
  666. Xextern char username[];
  667. X
  668. Xextern char *mustmalloc();
  669. X
  670. Xextern char *version, *shortversion;
  671. X
  672. X#define    MAXPAGE    2000
  673. X#ifdef    ALONE
  674. X#undef    PARTIAL
  675. X#undef    INCR
  676. X#endif
  677. END_OF_FILE
  678.   if test 11537 -ne `wc -c <'defs.h'`; then
  679.     echo shar: \"'defs.h'\" unpacked with wrong size!
  680.   fi
  681.   # end of 'defs.h'
  682. fi
  683. if test -f 'man/psroff.1.S' -a "${1}" != "-c" ; then 
  684.   echo shar: Will not clobber existing file \"'man/psroff.1.S'\"
  685. else
  686.   echo shar: Extracting \"'man/psroff.1.S'\" \(9407 characters\)
  687.   sed "s/^X//" >'man/psroff.1.S' <<'END_OF_FILE'
  688. X.\"Copyright 1988 by Chris Lewis 2.7 91/03/26
  689. X.TH PSROFF %%MANEXT%% "Psroff %%T2VERSION%%"
  690. X.SH NAME
  691. Xpsroff,ljroff,xxroff,catconv \- troff to PostScript or other printers
  692. X.SH SYNOPSIS
  693. X.IB xx roff
  694. X.BI "[\-T" xx "]"
  695. X.BI "[\-d" ptr "]"
  696. X.BI "[\-rL" length "]"
  697. X.BI "[\-P" prologs "]"
  698. X.BI "[\-D" deb "]"
  699. X[\-X] [\-M] [\-F]
  700. X.BI "[\-R" nn "]"
  701. X.BI "[\-O" off "]"
  702. X.BI "[\-Y" off "]"
  703. X.BI [ troffopts ]
  704. Xfiles ...
  705. X.sp
  706. X.I "troff filters"
  707. X|
  708. X.B %%LIBDIR%%/catconv
  709. X| psroff ...
  710. X.SH DESCRIPTION
  711. X.I Psroff
  712. Xis functionally equivalent for
  713. X.I troff
  714. Xfor printing on PostScript or HP Laserjet printers or via ditroff back-ends.
  715. X.I Troffopts
  716. Xcan be any of the normal
  717. X.I troff
  718. Xarguments, in particular \-m directives for specifying macro package.
  719. XNote that the semantics of "\-t" are changed - it means send the Postscript
  720. X(or HP Laserjet) output to stdout rather than the printer.
  721. X.PP
  722. XMost of the options you shouldn't need to use, except for
  723. X.IR troffopts ,
  724. Xand are for special (non-default)
  725. Xbehaviours:
  726. X.PP
  727. XThe ``\-X'' option does a ``set \-x'' for debugging the
  728. X.I psroff
  729. Xshell script.
  730. XThe ``\-Dopts'' option passes the ``\-Dopts'' debugging option through to
  731. X.IR troff2ps .
  732. XThe ``\-M'' option turns on printer metrics (if supported by the driver).
  733. XThe ``\-P'' options can be specified as many times as you want and are
  734. Xpassed through as special directives to the backend before the output
  735. Xpages start (see
  736. X.IR troff2ps (%%MANEXT%%)).
  737. XThe ``\-dptr'' option supplies ``ptr'' as the physical printer destination.
  738. X(analogous to ``\-d'' in UNIX System V lp).
  739. XThe ``\-Rnn'' option is passed to
  740. X.I troff2ps
  741. Xand will set the resolution of
  742. Xthe generated output (ditroff output only).
  743. XThe ``\-F'' option runs troff without
  744. X.RI troff2 xx
  745. Xso that you can see troff's error messages.
  746. X.PP
  747. XNote that \-m directives are parsed by
  748. X.I psroff
  749. Xitself, not
  750. X.IR troff ,
  751. Xand
  752. Xmust be invoked *after* \-T if \-T is used.
  753. X.PP
  754. X.I Psroff
  755. Xcan be made to generate several different printer output formats.
  756. XIf the environment variable PSROFF is set, it is used.
  757. XOtherwise, it looks at the characters
  758. Xprior to "roff" in the name it was invoked by.
  759. XThus, you can link "psroff" to "ljroff" - invocation of the latter will
  760. Xgenerate LaserJet codes.
  761. XAdditionally, you can override this by specifying
  762. Xthe
  763. X.RI \-T xx
  764. Xoption, where
  765. X.I xx
  766. Xwill select which printer codes to generate.
  767. X.PP
  768. XAs shipped, the
  769. X.I psroff
  770. X.RI \-T xx
  771. Xunderstands ``ps'' (postscript), ``tp'' (ditroff\(->tpscript also postscript),
  772. X``jt'' (ditroff\(->jetroff (HP PCL)),
  773. X``lj'' (HP PCL),
  774. Xand
  775. X``dt'' (Ditroff output, no printer).
  776. XHowever, this list may be different at your site - see
  777. Xthe
  778. X.I %%LIBDIR%%/lib/psrofflib
  779. Xfile.
  780. X.PP
  781. X.I Psroff
  782. Xinvokes
  783. X.I troff
  784. Xto do the document formatting, then sends the output
  785. Xto
  786. X.I troff2ps
  787. Xto do the generation of the correct printer codes.
  788. X.PP
  789. XSince
  790. X.I troff2ps
  791. Xrequires that it knows the page length, the "\-rL" option should be
  792. Xused (see the documentation for MM and
  793. X.I troff2ps
  794. Xfor more details).
  795. X.PP
  796. XThe "\-O" option allows you to specify a physical offset from the
  797. Xleft margin of the page.
  798. XNormal troff prohibits the total page offset plus line length from
  799. Xbeing greater than 7.54 inches, which means that it would be impossible
  800. Xto centre a 7.54 inch line on 8.5 inch wide paper.
  801. XThe default \-O is .5 inch (specified as .5i), which allows you to
  802. Xcentre a 7.5 inch line with a zero troff offset (.po directive).
  803. XThe .5 inch default was originally a hardcoded offset in
  804. X.IR troff2ps .
  805. XThe macro adapters have been tuned to centre the default line length
  806. Xin a 8.5 inch page.
  807. XThe value for the "\-O" option can take any form allowed by the "\-rL"
  808. Xoption in
  809. X.IR troffps .
  810. XThis is not implemented as "\-rO", because troff itself isn't supposed
  811. Xto know about it.
  812. XThe real line offset on a sheet of paper is the sum of the \-O and
  813. Xtroff page offset (.po directive).
  814. X.PP
  815. XThe "\-Y" option allows you to specify a vertical page offset,
  816. Xsimilar to "\-O" for horizontal.
  817. X.SH "DITROFF EMULATION"
  818. XWhen used with CAT troff,
  819. X.I psroff
  820. Xemulates a number of ditroff functions.
  821. XSuch as ``.sy''.
  822. XHowever, some of these extensions need a bit more help.
  823. XIn order to use the CAT troff emulation of extended ditroff characters,
  824. Xdrawing commands, or use with psfig (\eX'...') directives, you have to use
  825. X``catconv''.
  826. X.PP
  827. X.I Catconv
  828. Xis a Perl script that converts certain ditroff constructs into special
  829. Xrequests that CAT troff can be kludged into understanding, or at least,
  830. Xpassing it off to
  831. X.I troff2ps
  832. Xto interpret.
  833. X.I Catconv
  834. Xis a pure filter, and should be used thusly:
  835. X.RS
  836. X.nf
  837. Xfilters | catconv | psroff
  838. X.fi
  839. X.RE
  840. XAny troff input containing ``\eD'' or ``\eX'' or the extended character
  841. Xset (``\e(xx'') must be passed through catconv, otherwise, they won't work.
  842. X.PP
  843. XPsroff and troff2ps support the following drawing codes:
  844. X.RS
  845. X.nf
  846. X.ta 1.5i
  847. X\eD'l dx dy'    Draw line from here to here+(dx,dy)
  848. X\eD'c d'    Draw circle of diameter d, left side here
  849. X\eD'C d'    Ditto, filled
  850. X\eD'e x y'    Draw ellipse, diameter (x,y)
  851. X\eD'E x y'    Ditto, filled
  852. X\eD'a dx1 dy1 dx2 dy2'    Arc counterclockwise, start here.
  853. X    centre is dx1,dy1, end is dx2,dy2
  854. X\eD'~ x y x y ...'    Spline to x,y then to x,y ...
  855. X\eD'p x y x y ...'    Polygon to x,y, then x,y ... then to origin
  856. X\eD'P x y x y ...'    Ditto
  857. X\eD't x'    Set line thickness to x pixels
  858. X\eD'f d'    Set fill to d (0..1000, 0 is black)
  859. X.fi
  860. X.RE
  861. X.PP
  862. X``Standard'' DWB ditroff does not implement C, E, p, P, t or f.
  863. XBerkeley ditroff (including RS/6000 troff) and groff implement the whole
  864. Xlist.
  865. XDWB 3.1 might implement the whole list.
  866. X.SH MACROS
  867. XIncluded with the
  868. X.I psroff
  869. Xpackage is a set of macros called
  870. X.IR tmac.t2 .
  871. XThis is a set of extensions to and definitions for MM that we find useful.
  872. X.PP
  873. X.I psroff
  874. Xcomes with a series of macro adapters designed to make it work
  875. Xwith the least amount of grief with various macro packages.
  876. XIn order for this to work, whenever you specify the
  877. X.BI \-m macro
  878. Xoption,
  879. X.I psroff
  880. Xattempts to find a set of adapters for the specified macro package.
  881. XThe search path is as follows:
  882. X.BI %%LIBDIR%%/adapters/mac. type /tmac. macro ,
  883. X.BI %%LIBDIR%%/adapters/tmac. macro ,
  884. X.BI %%T2DIR%%/tmac. macro ,
  885. Xand finally
  886. X.BI %%RTMACDIR%%/tmac. macro .
  887. XWhere
  888. X.I type
  889. Xis the printer type (eg: ``ps'') and
  890. X.I macro
  891. Xis the macros you requested (eg: ``m'' for a request of ``\-mm'').
  892. XOnly the first
  893. X.BR tmac. macro
  894. Xfile found is used.
  895. X.PP
  896. XThe first two directories contain files with the following
  897. Xform:
  898. X.RS
  899. X.nf
  900. X\&.so %%LIBDIR%%/adapters/common.pre
  901. Xmacro specific prolog customization if necessary
  902. X\&.so <real macro package>
  903. Xmacro specific epilog customization if necessary
  904. X\&.so %%LIBDIR%%/adapters/common.post
  905. X.fi
  906. X.RE
  907. X.PP
  908. XThe intent is for
  909. X.BI adapters/mac. type /tmac. macro
  910. Xfiles to be adapters where the modifications have to be based on
  911. Xprinter type,
  912. Xand
  913. X.BI adapters/tmac. macro
  914. Xwhere the modifications are independent of the printer type.
  915. X.PP
  916. X.IR Psroff,
  917. Xas shipped comes with only printer independent adapters which have
  918. Xthe following customizations in
  919. X.BR common.pre :
  920. Xturn off ligatures,
  921. Xreload R, I, B, S font width tables,
  922. Xdefine ``.sR'' macro,
  923. Xand redefine ``.fp" directive to call both the built-in troff function ``.fp''
  924. Xand ``.sR''.
  925. X.B common.post
  926. Xmerely contains a disabling of ligatures (again).
  927. XThe macro-specific customization (as present) is simply the removal of
  928. Xcut marks.
  929. X.SH FILES
  930. X.if t .ta 2.5i
  931. X.if n .ta 3.5i
  932. X%%LIBDIR%%    Troff2ps library directory
  933. X.br
  934. X%%LIBDIR%%/adapters/mac.*    printer specific macro adapter directories
  935. X.br
  936. X%%LIBDIR%%/adapters/tmac.*    non-printer-specific macro adapters
  937. X.br
  938. X%%T2DIR%%/tmac.*    Psroff-originated macros
  939. X.br
  940. X%%LIBDIR%%/lib/psroff.lib    shell script configuration
  941. X.br
  942. X%%LIBDIR%%/lib/*    configuration files and default inclusions.
  943. Xetc.
  944. X.PP
  945. XNote that
  946. X.BR psroff and troff2ps
  947. Xwill search in the current directory first for library files, and then ./lib,
  948. Xand then %%LIBDIR%%/lib.
  949. X.SH "BUGS and FEATURES"
  950. XOld-fashioned CAT troff doesn't have a mechanism for passing arbitrary
  951. Xcommands to the CAT - eg: overlays, and physical font mounting etc.
  952. XIn order to support these things, a macro ".sR" was invented that
  953. Xpasses special directives to the back end by means of a magic pseudo
  954. XCAT code 'M', followed by an ASCII string containing the directive.
  955. XUnfortunately, the only way to get that to the back end from troff
  956. Xthat I have found so far is to embed the 'M<string>' in a ``.tm'' troff
  957. Xdirective.
  958. XThe ``.tm'' puts it's string to stderr, so psroff has been modified to
  959. Xmerge the stdout (CAT codes using \-t option to troff) and stderr (.tm
  960. Xdirectives) together.
  961. X.PP
  962. XUnfortunately, this means that you don't get to see troff-generated
  963. Xerrors except possibly as "illegal flash" errors from
  964. X.IR troff2ps ,
  965. Xor varying
  966. Xdegrees of extreme garbage on the printer.
  967. XIf you encounter mangled output, try running
  968. Xpsroff, with the ``\-F'' option.
  969. XThen you will see troff's stderr.
  970. X.PP
  971. XThe troff primitive ".tm" is renamed to ".tM" when using one of the
  972. Xsupplied macro adapters.
  973. X".tm" is now a macro which calls ".tM" with the appropriate arguments
  974. Xto pass the string straight through the stderr of
  975. X.IR troff2ps .
  976. XHence, traditional index macro handling and macro package errors will
  977. Xbe visible on the stderr of psroff.
  978. X.PP
  979. XAnother idiosyncrasy with MM is that if any ".sR" command is invoked
  980. Xbefore use of the ".MT" macro, the ".MT" macro will not work correctly.
  981. X(this includes ".fp"!).
  982. XThis is why the
  983. X.B \-P
  984. Xoption was invented.
  985. X.SH "SEE ALSO"
  986. Xtroff(1), troff2ps(%%MANEXT%%), mm(7?), cat(5).
  987. X.SH AUTHOR
  988. XWritten by Chris Lewis
  989. END_OF_FILE
  990.   if test 9407 -ne `wc -c <'man/psroff.1.S'`; then
  991.     echo shar: \"'man/psroff.1.S'\" unpacked with wrong size!
  992.   fi
  993.   # end of 'man/psroff.1.S'
  994. fi
  995. if test -f 'utils/calcfonts.S' -a "${1}" != "-c" ; then 
  996.   echo shar: Will not clobber existing file \"'utils/calcfonts.S'\"
  997. else
  998.   echo shar: Extracting \"'utils/calcfonts.S'\" \(10193 characters\)
  999.   sed "s/^X//" >'utils/calcfonts.S' <<'END_OF_FILE'
  1000. X#!/usr/bin/perl
  1001. Xeval "exec /usr/bin/perl -S $0 $*"
  1002. X    if $running_under_some_shell;
  1003. X#    Copyright 1985, 1986, 1987, 1988, 1989, 1990, 1991 Chris Lewis
  1004. X#        All Rights Reserved
  1005. X#
  1006. X#    See the LICENSE file for a full description of the restrictions
  1007. X#    under which this software is provided.
  1008. X#
  1009. X#Copyright 1991/02/20 Chris Lewis 2.2
  1010. X
  1011. X#    Set to path of sfp2pk if you have it, otherwise NULL.
  1012. X$sfp2pk    = '';
  1013. X#    Threshold for acceptable point sizes (default 10%).
  1014. X$thresh = 1.1;
  1015. X#    Place to build new fonts
  1016. X$newfonts = "/tmp/newfonts";
  1017. X#    You might also want to adjust the "do gen"'s at the end.
  1018. X
  1019. X#    Don't touch from here on.
  1020. X$basedir = `pwd`;
  1021. Xchop($basedir);
  1022. X@pointlist = (6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 28, 36);
  1023. X$verbose = 0;
  1024. X$dirlist = '';
  1025. X#    If non-null, each font matching this pattern not needed to
  1026. X#    build a particular size will be DELETED.
  1027. X$discardpat = "";
  1028. X
  1029. X$oldname = '';
  1030. X
  1031. Xsub discard {
  1032. X    local($file) = $_[0];
  1033. X    if ($discard && $file =~ $discardpat) {
  1034. X    unlink($file);
  1035. X    printf DISCARD ("deleted %s\n", $file);
  1036. X    }
  1037. X}
  1038. X
  1039. Xsub gen {
  1040. X    local($outf, $engname, $escape, $outtype) = ($_[0], $_[1], $_[2], $_[3]);
  1041. X    if ($sfontonly && $outf ne 'S') {
  1042. X    return;
  1043. X    }
  1044. X    @namelist = @_;
  1045. X    shift(namelist);
  1046. X    shift(namelist);
  1047. X    shift(namelist);
  1048. X    shift(namelist);
  1049. X    unlink("$outf.build");
  1050. X    foreach $pointsize (@pointlist) {
  1051. X    $found[$pointsize] = 0;
  1052. X    $missing = '';
  1053. X    $cmdline = "$basedir/pk2sfp -m \\\n";
  1054. X    $usedfonts = '';
  1055. X    $looklist = '';
  1056. X    for ($i = 0; $i <= $#namelist; $i++) {
  1057. X        ($rnamelist, $map) = split(/\//, $namelist[$i]);
  1058. X        $best = '';
  1059. X        $bestratio = 1000;
  1060. X        $tmplist = '';
  1061. X
  1062. X        @alternates = split(/,/, $rnamelist);
  1063. X        foreach $rname (@alternates) {
  1064. X        $ratio = $ratios{$rname, $pointsize};
  1065. X        if (!$ratio) {
  1066. X            $looked = "$rname(notfound)";
  1067. X        } else {
  1068. X            ($np, $size) = split(/ /, $table{$rname, $pointsize});
  1069. X            #$looked = sprintf("$rname$np.$size(%.2f)", $ratio);
  1070. X            $looked = sprintf("%s(%.2f)", $path{$rname, $pointsize},
  1071. X            $ratio);
  1072. X            if ($ratio && $ratio <= $bestratio) {
  1073. X            $best = $rname;
  1074. X            $bestratio = $ratio;
  1075. X            $bestentry = $looked;
  1076. X            }
  1077. X        }
  1078. X        $looklist .= "$looked\n";
  1079. X        $tmplist .= "$looked ";
  1080. X        }
  1081. X        if ($best && $bestratio <= $thresh) {
  1082. X        $usedfonts .= "$bestentry\n";
  1083. X        $tdir = $path{$best, $pointsize};
  1084. X        if (!$map) {
  1085. X            $map = $best;
  1086. X            if (! -r "$md/$map.$outtype") {
  1087. X            $map = $alternates[0];
  1088. X            }
  1089. X        }
  1090. X        if (! -r "$md/$map.$outtype") {
  1091. X            $missing .= sprintf("Map file $map (for entry %s)\n",
  1092. X            $namelist[$i]);
  1093. X        }
  1094. X        $cmdline .= "\t$md/$map.$outtype $tdir\\\n";
  1095. X        } else {
  1096. X        $missing .= "($tmplist) ";
  1097. X        }
  1098. X    }
  1099. X    if ($missing) {
  1100. X        chop($missing);
  1101. X        printf STDERR ("Missing $missing, won't generate $outf at $pointsize\n");
  1102. X        printf STDERR ("Acceptable ones: $usedfonts\n");
  1103. X    } else {
  1104. X        $cmdline .= "\t\t> t";
  1105. X        $found[$pointsize] = 1;
  1106. X        chop($usedfonts);
  1107. X        printf STDERR ("Generating $outf at $pointsize using $usedfonts\n");
  1108. X        if (system($cmdline)) {
  1109. X        printf STDERR ("failed ($!) $cmdline\n");
  1110. X        exit(1);
  1111. X        }
  1112. X        if (system("$basedir/pk2sfp t > $newfonts/$outf.$pointsize.sfp")) {
  1113. X        printf STDERR ("pk2sfp sort to build $outf.$pointsize.sfp failed\n");
  1114. X        exit(1);
  1115. X        }
  1116. X        unlink('t');
  1117. X        if ($sfp2pk) {
  1118. X        if (system("$sfp2pk < $newfonts/$outf.$pointsize.sfp " .
  1119. X            "> $newfonts/$outf.$pointsize.pk")) {
  1120. X            printf STDERR ("sfp2pk < $outf.$pointsize.sfp failed\n");
  1121. X            exit(1);
  1122. X        }
  1123. X        unlink("$newfonts/$outf.$pointsize.sfp");
  1124. X        }
  1125. X        close(GEN);
  1126. X    }
  1127. X    }
  1128. X    open(TABLE, ">>lj.fonts.new");
  1129. X# The second field can be truncated, but none of the others.
  1130. X#HI Helvetica-Italic \033(8U\033(s1p1s-3b04T nnnnpnnnnnnnnnn
  1131. X#HB Helvetica-Bold   \033(8U\033(s1p0s03b04T nnnnnnnnnnnnnnn
  1132. X    printf TABLE ("%-2s %-16.16s %-23s ", $outf, $engname, $escape);
  1133. X    foreach $pointsize (@pointlist) {
  1134. X    if ($found[$pointsize]) {
  1135. X        if ($sfp2pk) {
  1136. X        printf TABLE 'p';
  1137. X        } else {
  1138. X        printf TABLE 's';
  1139. X        }
  1140. X    } else {
  1141. X        printf TABLE 'n';
  1142. X    }
  1143. X    }
  1144. X    printf TABLE "\n";
  1145. X    close(TABLE);
  1146. X}
  1147. Xsub findcomplete {
  1148. X    foreach $name (sort keys(listofnames)) {
  1149. X    $complete{$name} = 0;
  1150. X    foreach $p (@pointlist) {
  1151. X        if ($ratios{$name, $p} <= $thresh) {
  1152. X        $complete{$name}++;
  1153. X        next;
  1154. X        }
  1155. X    }
  1156. X    }
  1157. X    foreach $name (sort keys(listofnames)) {
  1158. X    printf STDERR ("I have %d reasonable sizes of %s\n", $complete{$name},
  1159. X        $name);
  1160. X    }
  1161. X}
  1162. X
  1163. X
  1164. Xsub dumplist {
  1165. X    foreach $name (sort keys(listofnames)) {
  1166. X    foreach $p (@pointlist) {
  1167. X        ($rp, $rs) = split(/ /, $table{$name, $p});
  1168. X        printf STDERR ("%-8s %4d %4d %4d %4.4g%% %s\n",
  1169. X        $name, $p, $rp, $rs, (1 - $ratios{$name,$p}) * 100,
  1170. X        $path{$name, $p});
  1171. X    }
  1172. X    }
  1173. X}
  1174. X
  1175. Xwhile($arg = shift(@ARGV)) {
  1176. X    if ($arg eq '-v') {
  1177. X    $verbose = 1;
  1178. X    } elsif ($arg =~ /-S/) {
  1179. X    $sfontonly = 1;
  1180. X    } elsif ($arg =~ /^-D(.*)/) {
  1181. X    $basedir = $1;
  1182. X    } elsif ($arg =~ /^-s(.*)/) {
  1183. X    $sfp2pk = $1;
  1184. X    } elsif ($arg =~ /^-f(.*)/) {
  1185. X    $newfonts = $1;
  1186. X    } elsif ($arg !~ /^-/) {
  1187. X    if (-d $arg) {
  1188. X        $dirlist = "$dirlist $arg";
  1189. X    } else {
  1190. X        printf STDERR ("No directory %s, skipping\n", $arg);
  1191. X    }
  1192. X    } else {
  1193. X    printf STDERR ("calcfonts: bad option %s\n", $arg);
  1194. X    exit(1);
  1195. X    }
  1196. X}
  1197. X
  1198. Xif ($sfp2pk && ! -x $sfp2pk) {
  1199. X    printf STDERR
  1200. X    ("sfp2pk ($sfp2pk) not found - will generate SFP's not PK's\n");
  1201. X    $sfp2pk = '';
  1202. X}
  1203. X
  1204. Xif (!$dirlist) {
  1205. X    printf STDERR ("No directories to search - aborting\n");
  1206. X    exit(0);
  1207. X}
  1208. X
  1209. X$md = "$basedir/maps";
  1210. X$dirlist = "$basedir/fonts $dirlist";
  1211. X
  1212. Xunlink("$basedir/lj.fonts.new");
  1213. Xunlink("discard");
  1214. Xopen(DISCARD, ">discard");
  1215. X
  1216. X$cmdline =
  1217. X    "find $dirlist -type f '(' -name '*pk' -o -name '*.sfp' ')' -print";
  1218. Xprintf STDERR ("Commandline: $cmdline\n");
  1219. Xopen(INLIST, "$cmdline|") || die "Cannot start $cmdline\n";
  1220. X
  1221. Xwhile(<INLIST>) {
  1222. X    chop;
  1223. X    #/([a-z]+)([0-9]+)\s*:\s*(.*)/;
  1224. X    $path = $_;
  1225. X    if (/^\S+\/([a-z]+)([0-9]+)\.([0-9]+)pk/) {
  1226. X    $name = $1;
  1227. X    $points = $2;
  1228. X    $size = $3;
  1229. X    } elsif (/^\S+\/[a-z]+([0-9]+)\/([a-z]+)([0-9]+)\.pk/) {
  1230. X    $size = $1;
  1231. X    $name = $2;
  1232. X    $points = $3;
  1233. X    } elsif (/^\S+\/([a-z]+)([0-9]+)\.pk/) {
  1234. X    $size = 300;
  1235. X    $name = $1;
  1236. X    $points = $2;
  1237. X    } elsif (/^\S+\/([a-z]+)([0-9]+)\.sfp/) {
  1238. X    $size = 300;
  1239. X    $name = $1;
  1240. X    $points = $2;
  1241. X    } else {
  1242. X    printf STDERR ("Skipping %s\n", $path);
  1243. X    do discard($path);
  1244. X    next;
  1245. X    }
  1246. X    $listofnames{$name} = 1;
  1247. X    $actpoints = $points * $size / 300;
  1248. X#printf("path: $path, name: $name, points: $points");
  1249. X#printf(" size: $size, actpoints: $actpoints\n");
  1250. X    $foundany = 0;
  1251. X    foreach $needpoint (@pointlist) {
  1252. X    $ratio = $actpoints / $needpoint;
  1253. X    if ($ratio < 1) {
  1254. X        $ratio = 1 / $ratio;
  1255. X    }
  1256. X#printf("ratio: (to get %d) %.2f\n", $needpoint, $ratio);
  1257. X    if ($ratios{$name, $needpoint} eq '') {
  1258. X        $ratios{$name, $needpoint} = 100;
  1259. X    }
  1260. X
  1261. X    if ($ratio <= $ratios{$name, $needpoint}) {
  1262. X        $ratios{$name, $needpoint} = $ratio;
  1263. X        $table{$name, $needpoint} = "$points $size";
  1264. X        $refcnt{$path}++;
  1265. X        if ($path{$name, $needpoint}) {
  1266. X        $opath = $path{$name, $needpoint};
  1267. X        $refcnt{$opath}--;
  1268. X        if ($refcnt{$opath} == 0) {
  1269. X            printf DISCARD "%s\n", $opath;
  1270. X            do discard($opath);
  1271. X        }
  1272. X        }
  1273. X        $path{$name, $needpoint} = $path;
  1274. X        $foundany++;
  1275. X    }
  1276. X    }
  1277. X    if (!$foundany) {
  1278. X    do discard($path);
  1279. X    printf DISCARD "%s\n", $path;
  1280. X    }
  1281. X}
  1282. X
  1283. Xif ($verbose) {
  1284. X    do findcomplete();
  1285. X    do dumplist();
  1286. X}
  1287. X
  1288. X#    Example of do gen call:
  1289. X# do gen(
  1290. X#    'R',        Cat Troff name
  1291. X#    'Times-Roman',    English name (useful only in debugging)
  1292. X#    '\033(8U\033(s1p0s00b05T', Escape to emit if not present or builtin
  1293. X#    'ROMAN8',    map suffix to use.
  1294. X#    'cmr,jmr',    a font entry
  1295. X#    'cmsy,jmsy',    a font entry
  1296. X#    'cmti,jmti',    a font entry
  1297. X#    'cmtrf,jmtrf');    a font entry
  1298. X#
  1299. X# There can be any number of font entries, and it is of the following
  1300. X# generalized form:
  1301. X#
  1302. X#    <font>,<font>,<font>..../<map prefix>
  1303. X#
  1304. X#    Where: the list of fonts is a comma-separated list of
  1305. X#    PK/SFP font name prefixes of fonts that would be acceptable
  1306. X#    for merging with the other font entries to build the CAT font.
  1307. X#    A font with that prefix closest to each desired point size will
  1308. X#    be the one selected.  In case of ties, the later one wins in the
  1309. X#    list.  The map prefix (along with the suffix) is used to select
  1310. X#    which merge control file to use.  See pk2sfp and utils/maps.
  1311. X#    If omitted, the map prefix will default to the font prefix that
  1312. X#    it used if present.  If not present, it will default to the first
  1313. X#    font prefix.
  1314. X#    See LASERFONTS if you want more information on what the heck this
  1315. X#    junk is doing.
  1316. X
  1317. Xdo gen('R', 'Times-Roman', '\033(8U\033(s1p0s00b05T', 'ROMAN8',
  1318. X    'cmr,jmr', 'cmsy,jmsy', 'cmti,jmti', 'cmtrf,jmtrf');
  1319. X
  1320. Xdo gen('I', 'Times-Italic', '\033(8U\033(s1p1s-3b05T', 'ROMAN8',
  1321. X    'cmsl,jmsl/cmr', 'cmsy,jmsy', 'cmti,jmti', 'cmtrf,jmtrf');
  1322. X
  1323. Xdo gen('B', 'Times-Bold', '\033(8U\033(s1p0s03b05T', 'ROMAN8',
  1324. X    'cmbx,jmbx/cmr', 'cmsy,jmsy', 'cmti,jmti', 'cmtrf,jmtrf');
  1325. X
  1326. X#    Shipped with psroff (as PK's):
  1327. Xdo gen('S', 'Symbol', '\033(8M\033(s1p0s00b05T', 'MATH8',
  1328. X    'cmr,jmr', 'cmsy,jmsy', 'cmmi,jmmi', 'cmtrf,jmtrf');
  1329. X
  1330. Xdo gen('C', 'Courier', '\033(8U\033(s0p0s00b03T', 'ROMAN8',
  1331. X    'cmtt,cmvtt,jmtt/cmtt', 'cmsy,jmsy', 'cmti,jmti', 'cmtrf,jmtrf');
  1332. X
  1333. Xdo gen('CI', 'Courier-Italic', '\033(8U\033(s1p1s-3b03T', 'ROMAN8',
  1334. X    'cmit,cmsltt,jmit,jmsltt/cmtt', 'cmsy,jmsy', 'cmti,jmti', 'cmtrf,jmtrf');
  1335. X
  1336. Xdo gen('H', 'Helvetica', '\033(8U\033(s1p0s00b04T', 'ROMAN8',
  1337. X    'cmss,lcmss,jmss/cmr', 'cmsy,jmsy', 'cmti,jmti', 'cmtrf,jmtrf');
  1338. X
  1339. Xdo gen('HI', 'Helvetica-Italic', '\033(8U\033(s1p1s-3b04T', 'ROMAN8',
  1340. X    'cmssi,lcmssi,jmssi/cmr', 'cmsy,jmsy', 'cmti,jmti', 'cmtrf,jmtrf');
  1341. X
  1342. Xdo gen('HB', 'Helvetica-Bold', '\033(8U\033(s1p0s03b04T', 'ROMAN8',
  1343. X    'cmssb,lcmssb,jmssbx/cmr', 'cmsy,jmsy', 'cmti,jmti', 'cmtrf,jmtrf');
  1344. X
  1345. Xdo gen('E', 'English', '\033(8U\033(s1p0s00b05T', 'ROMAN8',
  1346. X    'eufm/alnum', 'cmr', 'cmsy,jmsy', 'cmti,jmti', 'cmtrf,jmtrf');
  1347. X
  1348. Xdo gen('EB', 'English-Bold', '\033(8U\033(s1p0s00b05T', 'ROMAN8',
  1349. X    'eufb/alnum', 'cmr', 'cmsy,jmsy', 'cmti,jmti', 'cmtrf,jmtrf');
  1350. X
  1351. X#"CI", "Courier-Italic", "\033(8U\033(s0p1s-3b03T", "ROMAN8",
  1352. X#"CB", "Courier-Bold", "\033(8U\033(s0p0s03b03T", "ROMAN8",
  1353. X#"L", "LinePrinter", "\033(8U\033(s0p0s00b00T", "ROMAN8",
  1354. X#"LI", "LinePrinter-Ital", "\033(8U\033(s0p1s-3b00T", "ROMAN8",
  1355. X#"LB", "LinePrinter-Bold", "\033(8U\033(s0p0s03b00T", "ROMAN8",
  1356. END_OF_FILE
  1357.   if test 10193 -ne `wc -c <'utils/calcfonts.S'`; then
  1358.     echo shar: \"'utils/calcfonts.S'\" unpacked with wrong size!
  1359.   fi
  1360.   # end of 'utils/calcfonts.S'
  1361. fi
  1362. if test -f 'widths/dit2catwid.c' -a "${1}" != "-c" ; then 
  1363.   echo shar: Will not clobber existing file \"'widths/dit2catwid.c'\"
  1364. else
  1365.   echo shar: Extracting \"'widths/dit2catwid.c'\" \(10841 characters\)
  1366.   sed "s/^X//" >'widths/dit2catwid.c' <<'END_OF_FILE'
  1367. X/*
  1368. X    Copyright 1985, 1986, 1987, 1988, 1989, 1990, 1991 Chris Lewis
  1369. X        All Rights Reserved
  1370. X
  1371. X    See the LICENSE file for a full description of restrictions under which
  1372. X    this software is provided.
  1373. X
  1374. X    Function:     converts ditroff tables to CAT troff.
  1375. X */
  1376. X
  1377. X#ifndef    lint
  1378. Xstatic char SCCSID[] =
  1379. X    "@(#)dit2catwid.c 2.7 Copyright 91/02/20 09:33:05 Chris Lewis";
  1380. X#endif
  1381. X
  1382. X#include <stdio.h>
  1383. X#include "../defs.h"
  1384. X#include <ctype.h>
  1385. X
  1386. X#ifndef    ASCIIWIDTHS
  1387. X
  1388. X#ifndef    FONTDIR
  1389. X#define    FONTDIR    "/usr/lib/font"
  1390. X#endif
  1391. X
  1392. X#ifndef    HEADERSIZE
  1393. X#    ifdef COFF
  1394. X#        include <aouthdr.h>
  1395. X#        include <filehdr.h>
  1396. X#        include <scnhdr.h>
  1397. X#        include <ldfcn.h>
  1398. X#        include <reloc.h>
  1399. X#        define H1 (sizeof (struct filehdr) + sizeof (struct aouthdr))
  1400. X#        define H2 (sizeof (struct scnhdr) + sizeof (struct reloc))
  1401. X#        define HEADERSIZE (H1 + H2)
  1402. X#    else
  1403. X#        include <a.out.h>
  1404. X#        define HEADERSIZE (sizeof (struct exec))
  1405. X#    endif
  1406. X#endif
  1407. X
  1408. X#endif
  1409. X
  1410. Xint res = 300;
  1411. Xint unitwid = 10;
  1412. Xint symfont = 0;
  1413. Xint verbose = 0;
  1414. Xint genc = 0;
  1415. Xint headersize = -1;
  1416. Xint ext = 0;
  1417. XFILE *extensions;
  1418. X
  1419. X#define    TROFFUWID    6
  1420. X
  1421. X#ifdef    DEBUG
  1422. X#undef    DEBUG
  1423. X#endif
  1424. X
  1425. XFILE *mustopen();
  1426. Xchar *mustmalloc();
  1427. X
  1428. Xextern struct cattab tabN[], tabS[];
  1429. X
  1430. Xchar *progname;
  1431. X
  1432. Xmain(argc, argv)
  1433. Xint argc; char **argv; {
  1434. X    extern char *optarg;
  1435. X    extern int optind;
  1436. X    char *p;
  1437. X    int c;
  1438. X
  1439. X    FILE *in1, *in2, *out;
  1440. X    char *fin1, *fin2, *fout;
  1441. X
  1442. X    progname = argv[0];
  1443. X
  1444. X    while ((c = getopt(argc, argv, "evsr:u:chH:")) != EOF)
  1445. X    switch(c) {
  1446. X        case 'h':
  1447. X#ifdef    ASCIIWIDTHS
  1448. X        printf("ascii\n");
  1449. X#else
  1450. X        printf("%d\n", HEADERSIZE);
  1451. X#endif
  1452. X        exit(0);
  1453. X        break;
  1454. X        case 'H':
  1455. X        headersize = atoi(optarg);
  1456. X        break;
  1457. X        case 's':
  1458. X        symfont = 1;
  1459. X        break;
  1460. X        case 'r':
  1461. X        res = atoi(optarg);
  1462. X        break;
  1463. X        case 'u':
  1464. X        unitwid = atoi(optarg);
  1465. X        break;
  1466. X        case 'e':
  1467. X        ext = 1;
  1468. X        break;
  1469. X        case 'v':
  1470. X        verbose = 1;
  1471. X        break;
  1472. X        case 'c':
  1473. X        genc = 1;
  1474. X        break;
  1475. X        default:
  1476. X        usage();
  1477. X    }
  1478. X    if (optind != argc - 3) {
  1479. X    usage();
  1480. X    }
  1481. X    in1 = mustopen(fin1 = argv[optind], "r");
  1482. X    in2 = mustopen(fin2 = argv[optind+1], "r");
  1483. X    out = mustopen(fout = argv[optind+2], "w");
  1484. X
  1485. X    process(in1, fin1);
  1486. X    if (ext) {
  1487. X    p = mustmalloc(strlen(argv[optind+2]+15), "extension file");
  1488. X    strcpy(p, argv[optind+2]);
  1489. X    strcat(p, ".ext");
  1490. X    extensions = mustopen(p, "w");
  1491. X    }
  1492. X    process(in2, fin2);
  1493. X    if (ext)
  1494. X    fclose(extensions);
  1495. X
  1496. X    sort(tabS);
  1497. X    sort(tabN);
  1498. X
  1499. X    if (genc) {
  1500. X    if (symfont)
  1501. X        genccode(tabS, out, fout, "Symbol character set");
  1502. X    else
  1503. X        genccode(tabN, out, fout, "Normal character set");
  1504. X    } else {
  1505. X    if (symfont)
  1506. X        output(tabS, out, fout, "Symbol character set");
  1507. X    else
  1508. X        output(tabN, out, fout, "Normal character set");
  1509. X    }
  1510. X    fclose(in1);
  1511. X    fclose(in2);
  1512. X    fclose(out);
  1513. X    exit(0);
  1514. X}
  1515. X
  1516. Xgenccode(symset, f, file, type)
  1517. XFILE *f;
  1518. Xstruct cattab *symset;
  1519. Xchar *type, *file; {
  1520. X    int i, j;
  1521. X
  1522. X    fprintf(f, "/* %s */\n", type);
  1523. X    fprintf(f, "char ftXX[224] = {\n");
  1524. X
  1525. X    for (i = 0, j = 0; i < 224; i++) {
  1526. X    /* skip to next valid CAT char */
  1527. X    while(symset[j].ch_name && !symset[j].ch_name[0])
  1528. X        j++;
  1529. X
  1530. X    /* not the right position yet */
  1531. X    if (!symset[j].ch_name || i < symset[j].ch_wididx) {
  1532. X        gencline(f, i, 0, NULL);
  1533. X        continue;
  1534. X    }
  1535. X
  1536. X    if (symset[j].ch_wididx != i) {
  1537. X        fprintf(stderr, "GFNTTAB: index mismatch: (%d/%d)\n",
  1538. X        i, j);
  1539. X        exit(1);
  1540. X    }
  1541. X
  1542. X    if (!(symset[j].ch_info&0x3f)) {
  1543. X        printf("INFO: No width for %s (index %d, file %s)\n",
  1544. X        symset[j].ch_name, symset[j].ch_wididx, file);
  1545. X        gencline(f, i, symset[0].ch_info, symset[j].ch_name);
  1546. X    } else
  1547. X        gencline(f, i, symset[j].ch_info, symset[j].ch_name);
  1548. X    j++;
  1549. X    }
  1550. X
  1551. X    fprintf(f, "};\n");
  1552. X    dumpset(symset, "After C Dump");
  1553. X
  1554. X    if (symset[j].ch_name) {
  1555. X    fprintf(stderr, "GFNTTAB: table error (too long: %d left: %s)\n",
  1556. X        j, symset[j].ch_name);
  1557. X    exit(1);
  1558. X    }
  1559. X}
  1560. X
  1561. Xgencline(file, index, width, name)
  1562. XFILE *file; int index, width; char *name; {
  1563. X    int w = width&077;
  1564. X    int k = width&0300;
  1565. X    fprintf(file, "\t%2d", w);
  1566. X    if (k)
  1567. X    fprintf(file, "+0%03o", k);
  1568. X    if (index != 223)
  1569. X    fprintf(file, ",");
  1570. X    if (name && *name) {
  1571. X    if (!k)
  1572. X        fprintf(file, "\t");
  1573. X    fprintf(file, "\t/* %s */\n", name);
  1574. X    } else
  1575. X    fprintf(file, "\n");
  1576. X}
  1577. X
  1578. Xoutput(symset, f, file, type)
  1579. XFILE *f;
  1580. Xstruct cattab *symset;
  1581. Xchar *type, *file; {
  1582. X    int i, j;
  1583. X
  1584. X#ifdef    ASCIIWIDTHS
  1585. X#define    EMITWID(v,f)    fprintf(f, "%d\n", v)
  1586. X#else
  1587. X#define    EMITWID(v,f)    fputc(v, f)
  1588. X
  1589. X    FILE *of = (FILE *) NULL;
  1590. X    /* If headersize != 0 AND there's a FONTDIR/ftR, output
  1591. X       the first headersize bytes of it, then the new width table,
  1592. X       then the trailing bytes of FONTDIR/ftR.  If there's
  1593. X       no FONTDIR/ftR, we just prepend headersize 0's.
  1594. X       The reason for this is that some troff's insist on valid
  1595. X       headers.
  1596. X    */
  1597. X
  1598. X    if (headersize == -1)
  1599. X    headersize = HEADERSIZE;
  1600. X
  1601. X    if (headersize != 0) {
  1602. X    char buf[128];
  1603. X    sprintf(buf, "%s/%s", FONTDIR, "ftR");
  1604. X    if (of = fopen(buf, "r")) {
  1605. X        for (i = 0; i < headersize; i++)
  1606. X        fputc(fgetc(of), f);
  1607. X        for (i = 0; i < 224; i++)
  1608. X        fgetc(of);
  1609. X        if (feof(of)) {
  1610. X        fclose(of);
  1611. X        of = (FILE *) NULL;
  1612. X        }
  1613. X    } else {
  1614. X        for (i = 0; i < headersize; i++)
  1615. X        fputc('\0', f);
  1616. X    }
  1617. X    }
  1618. X#endif
  1619. X
  1620. X    for (i = 0, j = 0; i < 224; i++) {
  1621. X
  1622. X    /* skip to next valid CAT char */
  1623. X    while(symset[j].ch_name && !symset[j].ch_name[0])
  1624. X        j++;
  1625. X
  1626. X    /* not the right position yet */
  1627. X    if (!symset[j].ch_name || i < symset[j].ch_wididx) {
  1628. X        EMITWID('\0', f);
  1629. X        continue;
  1630. X    }
  1631. X
  1632. X    if (symset[j].ch_wididx != i) {
  1633. X        fprintf(stderr, "GFNTTAB: index mismatch: (%d/%d)\n",
  1634. X        i, j);
  1635. X        exit(1);
  1636. X    }
  1637. X
  1638. X    if (!(symset[j].ch_info&0x3f)) {
  1639. X        printf("INFO: No width for %s (index %d, file %s)\n",
  1640. X        symset[j].ch_name, symset[j].ch_wididx, file);
  1641. X        EMITWID(symset[0].ch_info, f);
  1642. X    } else
  1643. X        EMITWID(symset[j].ch_info, f);
  1644. X    j++;
  1645. X    }
  1646. X
  1647. X#ifndef    ASCIIWIDTHS
  1648. X    if (of) {
  1649. X    while((i = fgetc(of)) != EOF)
  1650. X        fputc(i, f);
  1651. X    fclose(of);
  1652. X    }
  1653. X#endif
  1654. X
  1655. X    dumpset(symset, "After CAT dump");
  1656. X
  1657. X    if (symset[j].ch_name) {
  1658. X    fprintf(stderr, "GFNTTAB: table error (too long: %d left: %s)\n",
  1659. X        j, symset[j].ch_name);
  1660. X    exit(1);
  1661. X    }
  1662. X}
  1663. X
  1664. Xdumpset(symset, str)
  1665. Xstruct cattab *symset;
  1666. Xchar *str; {
  1667. X    int i, j;
  1668. X    if (verbose) {
  1669. X    printf("\n%s:\n", str);
  1670. X    for (i = 0; symset[i].ch_name; i++) {
  1671. X        if (strlen(symset[i].ch_name) == 0)
  1672. X        continue;
  1673. X        printf(" %4d", symset[i].ch_wididx);
  1674. X        printf("    %d+%03o,",
  1675. X        symset[i].ch_info & 077, symset[i].ch_info & 0300);
  1676. X        if (symset[i].ch_name)
  1677. X        printf ("    /* \"%s\" */\n", symset[i].ch_name);
  1678. X        else
  1679. X        printf ("\n");
  1680. X    }
  1681. X    }
  1682. X}
  1683. X
  1684. Xusage() {
  1685. X    fprintf(stderr, "usage: %s [-rres] [-uunitwid] normfont symfont output\n",
  1686. X    progname);
  1687. X    exit(1);
  1688. X}
  1689. X
  1690. Xchar *
  1691. Xmustmalloc(n)
  1692. Xregister int n; {
  1693. X    register char *p;
  1694. X    extern char *malloc();
  1695. X    p = malloc(n);
  1696. X    if (!p) {
  1697. X    fprintf(stderr, "%s: cannot alloc %d bytes\n", progname, n);
  1698. X    exit(1);
  1699. X    } else
  1700. X    return(p);
  1701. X}
  1702. X
  1703. XFILE *
  1704. Xmustopen(f, mode)
  1705. Xchar *f, *mode; {
  1706. X    FILE *desc;
  1707. X    if ((desc = fopen(f, mode)) == NULL) {
  1708. X    fprintf(stderr, "%s: cannot open file %s mode %s\n", progname, f, mode);
  1709. X    exit(1);
  1710. X    } else
  1711. X    return(desc);
  1712. X}
  1713. X
  1714. Xchar *gettoken();
  1715. X
  1716. Xprocess(f, filename)
  1717. XFILE *f;
  1718. Xchar *filename; {
  1719. X    char *sv;
  1720. X    char buffer[512];
  1721. X    char *tok;
  1722. X    int commentsok = 1;
  1723. X    int widval, oldwidval;
  1724. X    int eval, oldeval;
  1725. X    while(fgets(buffer, sizeof(buffer), f) && buffer[0] == '#');
  1726. X
  1727. X    if (feof(f))    /* NULL file */
  1728. X    return;
  1729. X
  1730. X    do {
  1731. X    tok = gettoken(buffer, NULL);
  1732. X
  1733. X    if (!tok)
  1734. X        continue;
  1735. X    if (0 == strcmp(tok, "charset"))
  1736. X        break;
  1737. X
  1738. X    if (0 == strcmp(tok, "spacewidth")) {
  1739. X        if (!(tok = gettoken(buffer, 1))) {
  1740. X        fprintf(stderr, "%s: bad spacewidth line in %s\n",
  1741. X            progname, filename);
  1742. X        exit(1);
  1743. X        }
  1744. X        widval = atoi(tok);
  1745. X        widval = ((double) TROFFUWID * TROFFRESOLUTION * widval /
  1746. X        (unitwid * res)) + .5;
  1747. X        update(tabS, " ", widval);
  1748. X        update(tabN, " ", widval);
  1749. X        update(tabS, "\\|", widval / 2);
  1750. X        update(tabN, "\\|", widval / 2);
  1751. X        update(tabS, "\\^", widval / 4);
  1752. X        update(tabN, "\\^", widval / 4);
  1753. X    }
  1754. X    } while(fgets(buffer, sizeof(buffer), f));
  1755. X
  1756. X    if (strcmp(tok, "charset")) {
  1757. X    fprintf(stderr, "%s: %s bad format - no charset line\n", progname,
  1758. X        filename);
  1759. X    exit(1);
  1760. X    }
  1761. X    while(fgets(buffer, sizeof(buffer), f)) {
  1762. X    char str[3];
  1763. X    if (commentsok && buffer[0] == '#')
  1764. X        continue;
  1765. X    if (strlen(buffer) > 1 && buffer[0] == '#' && !isspace(buffer[1]))
  1766. X        continue;
  1767. X    commentsok = 0;
  1768. X#ifdef    DEBUG
  1769. X    printf("buffer: %s\n", buffer);
  1770. X#endif
  1771. X    tok = gettoken(buffer, NULL);
  1772. X    if (!tok)
  1773. X        continue;
  1774. X    if (strlen(tok) > 2) {
  1775. X        fprintf(stderr, "%s: %s bad format on line %s\n",
  1776. X        progname, filename, buffer);
  1777. X        exit(1);
  1778. X    }
  1779. X    strcpy(str, tok);
  1780. X    tok = gettoken(buffer, 1);
  1781. X    if (!tok) {
  1782. X        fprintf(stderr, "%s: %s bad format on line %s\n",
  1783. X        progname, filename, buffer);
  1784. X        exit(1);
  1785. X    }
  1786. X    if (tok[0] == '#' && !isspace(tok[1]))
  1787. X        continue;
  1788. X#ifdef    DEBUG
  1789. X    printf("token: %s\n", tok);
  1790. X#endif
  1791. X    if (0 == strcmp(tok, "\"")) {
  1792. X        widval = oldwidval;
  1793. X        eval = oldeval;
  1794. X    } else {
  1795. X        widval = ((double) TROFFUWID * TROFFRESOLUTION * atoi(tok) /
  1796. X        (unitwid * res)) + .5;
  1797. X        widval = max(widval, 1);
  1798. X        tok = gettoken(buffer, 1);
  1799. X        if (!tok) {
  1800. X        fprintf(stderr, "%s: %s bad format on line %s\n",
  1801. X            progname, filename, buffer);
  1802. X        exit(1);
  1803. X        }
  1804. X        widval |= (atoi(tok) << 6);
  1805. X        tok = gettoken(buffer, 1);
  1806. X        if (!tok) {
  1807. X        if (verbose)
  1808. X            fprintf(stderr, "%s: %s missing emit code on line %s\n",
  1809. X            progname, filename, buffer);
  1810. X        } else
  1811. X        sscanf(tok, "%o", &eval);
  1812. X    }
  1813. X    if (0 == (update(tabS, str, widval) + update(tabN, str, widval))) {
  1814. X        if (extensions)
  1815. X        fprintf(extensions, "%s\t%s\t%04o\n", str,
  1816. X            symfont? "S": "N", eval);
  1817. X    }
  1818. X    oldeval = eval;
  1819. X    oldwidval = widval;
  1820. X    }
  1821. X}
  1822. X
  1823. Xupdate(table, str, val)
  1824. Xstruct cattab *table;
  1825. Xchar *str;
  1826. Xint val; {
  1827. X    int i;
  1828. X    int done = 0;
  1829. X
  1830. X#ifdef    DEBUG
  1831. X    printf("Inserting char %s, (%03o)\n", str, val);
  1832. X#endif
  1833. X
  1834. X    for (i = 0; table[i].ch_name; i++)
  1835. X    if (str && 0 == strcmp(table[i].ch_name, str)) {
  1836. X        if (verbose && table[i].ch_info && table[i].ch_info != val)
  1837. X        fprintf(stderr, "Duplicate nonequal width entry (%s/%s:%x/%x)\n",
  1838. X            table[i].ch_name, str, table[i].ch_info, val);
  1839. X        table[i].ch_info = val;
  1840. X        done = 1;
  1841. X    }
  1842. X    return(done);
  1843. X}
  1844. X
  1845. Xchar *
  1846. Xgettoken(buf, ptr)
  1847. Xchar *buf, *ptr; {
  1848. X    static char *saveptr;
  1849. X    static char savebuf[512];
  1850. X    char *bp = savebuf;
  1851. X    if (!ptr)
  1852. X    saveptr = buf;
  1853. X    while(*saveptr && isspace(*saveptr)) saveptr++;
  1854. X    if (*saveptr)
  1855. X    while(*saveptr && !isspace(*saveptr))
  1856. X        *bp++ = *saveptr++;
  1857. X    *bp = '\0';
  1858. X    if (savebuf[0])
  1859. X    return(savebuf);
  1860. X    else
  1861. X    return((char *) NULL);
  1862. X}
  1863. X
  1864. Xtabcmp(a, b)
  1865. Xstruct cattab *a, *b; {
  1866. X    return(a->ch_wididx - b->ch_wididx);
  1867. X}
  1868. X
  1869. Xsort(table)
  1870. Xstruct cattab *table; {
  1871. X    register int i;
  1872. X
  1873. X    for (i = 0; table[i].ch_name; i++);
  1874. X
  1875. X    qsort(table, i, sizeof(struct cattab), tabcmp);
  1876. X
  1877. X    dumpset(table, "After Sort");
  1878. X}
  1879. END_OF_FILE
  1880.   if test 10841 -ne `wc -c <'widths/dit2catwid.c'`; then
  1881.     echo shar: \"'widths/dit2catwid.c'\" unpacked with wrong size!
  1882.   fi
  1883.   # end of 'widths/dit2catwid.c'
  1884. fi
  1885. echo shar: End of archive 9 \(of 19\).
  1886. cp /dev/null ark9isdone
  1887. MISSING=""
  1888. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ; do
  1889.     if test ! -f ark${I}isdone ; then
  1890.     MISSING="${MISSING} ${I}"
  1891.     fi
  1892. done
  1893. if test "${MISSING}" = "" ; then
  1894.     echo You have unpacked all 19 archives.
  1895.     echo "Read the README to get started with psroff installation"
  1896.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1897. else
  1898.     echo You still must unpack the following archives:
  1899.     echo "        " ${MISSING}
  1900. fi
  1901. exit 0
  1902.  
  1903. exit 0 # Just in case...
  1904.